Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add query level cache logic #311

Merged
merged 2 commits into from
Oct 21, 2024
Merged

Conversation

loadez
Copy link
Collaborator

@loadez loadez commented Sep 16, 2024

Creates the basic logic for caching database queries, currently it will only be applied to the slowest query.

Test by going to a tree details page and filtering the tests or boots tabs, the first load should be normal but any other filtering by status should be faster.

Closes: #301

@loadez loadez self-assigned this Sep 16, 2024
@loadez loadez marked this pull request as draft September 17, 2024 11:53
@loadez loadez marked this pull request as ready for review September 17, 2024 13:25
from datetime import timedelta
import re

DEFAULT_QUERY_TIME_INTERVAL = {'days': 7}
DEFAULT_QUERY_CACHE = 180
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an env var right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in debug this should be 0 also

Copy link
Collaborator

@lfjnascimento lfjnascimento left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big win, working beautifully!


def getQueryCache(key, params: dict):
params_hash = __createCacheParamsHash(params)
return cache.get("%s-%s" % (key, hash(params_hash)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are already hashing the params in __createCacheParamsHash

def setQueryCache(key, params, rows, commit_hash=None, build_id=None, test_id=None,
timeout=DEFAULT_QUERY_CACHE):
params_hash = __createCacheParamsHash(params)
hash_key = "%s-%s" % (key, hash(params_hash))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto about params already being hashed in createCacheParamsHash

print(ex)


def __addToLookup(key, value, lookup):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these names are a little confusing

maybe this could be cacheKey and instead of value it could be specificPropertyKey
because the value is being used as the key

@MarceloRobert MarceloRobert self-assigned this Oct 9, 2024
WilsonNet
WilsonNet previously approved these changes Oct 16, 2024
Copy link
Collaborator

@WilsonNet WilsonNet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@MarceloRobert MarceloRobert force-pushed the feat/query-level-cache branch 2 times, most recently from 0a3c547 to 1300532 Compare October 16, 2024 18:15
@WilsonNet WilsonNet dismissed their stale review October 16, 2024 18:47

just noticed it is removing the view page cache but we still need for the tree listing slow

@@ -206,7 +206,7 @@ def __getitem__(self, item):
CSRF_COOKIE_SECURE = False
SECURE_SSL_REDIRECT = False
SECURE_HSTS_SECONDS = 3600
CACHE_TIMEOUT = 0
CACHE_TIMEOUT = 60
Copy link
Collaborator

@WilsonNet WilsonNet Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want debug without cache as the default behavior, otherwise it get's annoying to develop since every change will take one minute to reflect

@MarceloRobert MarceloRobert merged commit 6ab3aea into main Oct 21, 2024
5 checks passed
@MarceloRobert MarceloRobert deleted the feat/query-level-cache branch October 24, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add query level caching
4 participants